package edu.towson.cosc603.lily.server;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StutterWords{
	public static String stutter(String text){
	 Scanner s = null;
     List<String> list = new ArrayList<String>();
     String str;
     String report = "";
     String[] string = new String[1000];
     int l = 1;
     try {
             s = new Scanner(text); 
             while(s.hasNextLine()){ 
                str = s.nextLine();
                string = str.split(" ");
                for (int i=0; i<string.length; i++ )
                  list.add(string[i]);
                  while(!list.isEmpty()){
                  int count =1;
                  String first = (String)list.get(0);
                  for(int j=1; j<list.size(); j++){
                    String repeat = (String)list.get(j);
                    if(first.equals(repeat)){
                      count ++ ;
                      list.remove(repeat);
         }
      } 
           if(count > 1 )
           report=report +"  Repeated word on line "+l+": "+first+";";
           list.remove(first);
         }
         l++;
     }
           if(report == "")
           return "no repeat";
           return report;
     }
     finally {
         if (s != null) {
             s.close();
         }
     }
}
}

